package com.ziyun.erp.web.modules.freightages.controller;

import com.ziyun.erp.modules.freightages.entity.FreightAreaEntity;
import com.ziyun.erp.modules.freightages.service.FreightAreaService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 运费地址表
 *
 * @author 
 * @email 
 * @date 2018-08-10 15:38:32
 */
@RestController
@RequestMapping("freightages/freightarea")
public class FreightAreaController {
    @Autowired
    private FreightAreaService freightAreaService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("freightages:freightarea:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = freightAreaService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{freightAreaId}")
    @RequiresPermissions("freightages:freightarea:info")
    public R info(@PathVariable("freightAreaId") Integer freightAreaId){
        FreightAreaEntity freightArea = freightAreaService.selectById(freightAreaId);

        return R.ok().put("freightArea", freightArea);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("freightages:freightarea:save")
    public R save(@RequestBody FreightAreaEntity freightArea){
        freightAreaService.insert(freightArea);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("freightages:freightarea:update")
    public R update(@RequestBody FreightAreaEntity freightArea){
        ValidatorUtils.validateEntity(freightArea);
        freightAreaService.updateAllColumnById(freightArea);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("freightages:freightarea:delete")
    public R delete(@RequestBody Integer[] freightAreaIds){
        freightAreaService.deleteBatchIds(Arrays.asList(freightAreaIds));

        return R.ok();
    }

}
